﻿Imports System.Data
Imports System.Data.SqlClient

Partial Class reset
    Inherits System.Web.UI.Page

    Dim connString As String = "Data Source=sql2008.campus.jcu.edu ; Initial Catalog=service; User Id=Thunder48; Password=Thundertech169;"
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'Make sure it's not the admin
        If Session("driver_id") Is Nothing Then
            Session("loggedin") = False
            Response.Redirect("default.aspx")
        End If
    End Sub
    Protected Sub submitButton_Click(sender As Object, e As System.EventArgs) Handles submitButton.Click

        Dim conn As New SqlConnection
        Dim cmd As String
        Dim sql As SqlCommand = New SqlCommand
        Dim newpw As String
        'Dim reader As SqlDataReader
        conn.ConnectionString = connString
        conn.Open()

        'cmd = "select id,password,first_name,last_name,email from Driver where email='" & email.Text & "' and [password]='" & password.Text & "'"
        newpw = passwordTextbox.Text
        cmd = "UPDATE Driver SET password='" & newpw & "' WHERE [id]=" & Session("driver_id")

        sql.CommandText = cmd
        sql.Connection = conn
        Try
            sql.ExecuteNonQuery()
            Response.Redirect("logout.aspx")
        Catch ex As Exception

        End Try



        'reader = sql.ExecuteReader()
        '
        'If reader.HasRows Then
        '    'Response.Redirect("portal.aspx")
        '    Try
        '        reader.Read()
        '        'Session("username") = reader.GetString(0)
        '        'Session("password") = reader.GetString(1)
        '        'Session("firstname") = reader.GetString(2)
        '        'Session("lastname") = reader.GetString(3)
        '
        '        Session("driver_id") = reader.GetValue(0)
        '        Session("first_name") = reader.GetString(2)
        '        Session("last_name") = reader.GetString(3)
        '        Session("email") = reader.GetString(4)
        '        Session("semester") = getSemester()
        '        Session("loggedin") = True
        '
        '        Dim pw As String = reader.GetString(1)
        '        If pw = "cssa" Then
        '            Response.Redirect("reset.aspx")
        '        Else
        '            Response.Redirect("portal.aspx")
        '        End If
        '
        '
        '    Catch
        '        failureLabel.Text = "Fatal error."
        '    End Try
        '    'Response.Write("Success!")
        '    'While (reader.Read)
        '    'reader.Read()
        '    'Response.Write(reader.GetString(0) & reader.GetString(1))
        '    'End While
        'Else
        '    failureLabel.Text = "Login / Password does not exist."
        '
        'End If
    End Sub
End Class
